﻿using AutoMapper;
using QuanLyGiaoVuDAL.DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace QuanLyGiaoVuUI.Models.MonHoc
{
    public class MonHocViewModel
    {
        public System.Guid ID { get; set; }

        [Display(Name="Mã môn học")]
        public string MaMonHoc { get; set; }

        [Display(Name="Tên môn học")]
        public string TenMonHoc { get; set; }

        [Display(Name="Tổng số tín chỉ")]
        public short TongSoTinChi { get; set; }

        [Display(Name="Số tín chỉ lý thuyết")]
        public short SoTinChiLyThuyet { get; set; }

        [Display(Name="Học kỳ")]
        public short HocKy { get; set; }

        public System.Nullable<System.Guid> MaMonChinh { get; set; }

        public MonHocDTO MonHocChinh { get; set; }

        public IEnumerable<LopSinhVienDTO> DanhSachLop { get; set; }

        public MonHocDTO ToMonHocDTO()
        {
            Mapper.CreateMap(typeof(MonHocViewModel),typeof(MonHocDTO));
            var monHocDTO = new MonHocDTO();
            Mapper.Map(this, monHocDTO);
            return monHocDTO;
        }

        public static MonHocViewModel FromMonHocDTO(MonHocDTO monHocDTO)
        {
            Mapper.CreateMap(typeof(MonHocDTO), typeof(MonHocViewModel));
            var monHocViewModel = new MonHocViewModel();
            Mapper.Map(monHocDTO, monHocViewModel);
            return monHocViewModel;
        }

        public static IEnumerable<MonHocViewModel> FromMonHocDTOList(IEnumerable<MonHocDTO> monHocDTOList)
        {
            List<MonHocViewModel> monHocViewModelList = new List<MonHocViewModel>();
            foreach (MonHocDTO monHocDTO in monHocDTOList)
            {
                monHocViewModelList.Add(MonHocViewModel.FromMonHocDTO(monHocDTO));
            }
            return monHocViewModelList.AsEnumerable<MonHocViewModel>();
        }
    }
}